import { reactive } from "vue";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "海外仓运单号",
    keyName: "warehouseBillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "select",
    label: "审批状态",
    keyName: "state",
    optConfig: {
      label: "label",
      value: "value"
    },
    options: [
      {
        label: "待审批",
        value: 3
      },
      {
        label: "审批通过",
        value: 5
      },
      {
        label: "审批驳回",
        value: 4
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "跟单员",
    keyName: "followIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "5", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },

    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "审批人",
    keyName: "finIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "6", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "拣货时间",
    keyName: "depositTime"
  }
];

export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50"
  },
  {
    field: "warehouseBillNum",
    title: "海外仓运单号",
    minWidth: "220",
    renderSlot: "warehouseBillNum"
  },
  {
    field: "customerName",
    title: "客户简称",
    minWidth: "120",
    sortable: true
  },
  {
    field: "companyName",
    title: "客户名称",
    minWidth: "120"
  },

  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "135",
    formatter: "formatDate",
    sortable: true
  },
  {
    field: "channelName",
    title: "渠道",
    minWidth: "140",
    sortable: true
  },
  {
    field: "itemNumber",
    title: "件数",
    minWidth: "80"
  },
  {
    field: "squaresNumber",
    title: "方数",
    minWidth: "80"
  },
  {
    field: "receiveBillAmount",
    title: "应收款",
    minWidth: "90"
  },
  {
    field: "declaredValue",
    title: "申报价值",
    minWidth: "100"
  },
  {
    field: "bizName",
    title: "业务员",
    minWidth: "80",
    sortable: true
  },
  {
    field: "followName",
    title: "跟单员",
    minWidth: "100",
    sortable: true
  },
  {
    field: "finName",
    title: "审批人",
    minWidth: "80",
    sortable: true
  },
  {
    field: "remark",
    title: "客户备注",
    minWidth: "80"
  },
  {
    field: "innerRemark",
    title: "内部备注",
    minWidth: "80"
  },
  {
    field: "state",
    title: "审批状态",
    minWidth: "110",
    renderSlot: "state",
    sortable: true
  },
  {
    field: "action",
    title: "操作",
    minWidth: "140",
    fixed: "right",
    renderSlot: "action"
  }
];
